/*
 * @Description: 
 * @Author: fhw
 * @Date: 2022-11-18 11:13:34
 */
import { ApiProperty } from '@nestjs/swagger';
import { ChatUser } from 'src/chat_user/entities/chat_user.entity';
import { PaginatedResult } from 'src/common/entities/entities';
import { GroupChat } from 'src/group-chat/entities/group-chat.entity';
import {
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
} from 'typeorm';

@Entity('chat_user_group')
export class ChatUserGroup {
  @ApiProperty({ example: 'id', description: 'id' })
  @PrimaryGeneratedColumn({
    type: 'int',
    comment: 'id',
  })
  id: number;

  @ApiProperty({ example: 'userId', description: '用户id' })
  @Column({
    type: 'int',
    comment: '用户id',
  })
  userId: number;

  @ApiProperty({ example: 'group_id', description: '群id' })
  @Column({
    type: 'varchar',
    comment: '群id',
  })
  group_id: string;

  @ApiProperty({
    example: 'is_management',
    description: '是否是管理员：1是，0不是',
  })
  @Column({
    type: 'tinyint',
    comment: '是否是管理员：1是，0不是',
    default: 0,
  })
  is_management: number;

  @ApiProperty({
    example: 'is_join',
    description: '是否加入：0发起邀请，1加入，2拒绝，3申请中',
  })
  @Column({
    type: 'tinyint',
    comment: '是否加入：0发起邀请，1加入，2拒绝，3申请中',
    default: 0,
  })
  is_join: number;

  @ApiProperty({ example: 'note', description: '群备注' })
  @Column({
    type: 'varchar',
    comment: '群备注',
    default: 0,
  })
  note: string;

  @ApiProperty({ example: 'unread_num', description: '未读消息数量' })
  @Column({
    type: 'tinyint',
    comment: '未读消息数量',
    default: 0,
  })
  unread_num: number;

  @ApiProperty({ example: 'date', description: '创建时间' })
  @CreateDateColumn({
    type: 'datetime',
    comment: '创建时间',
  })
  createDate: string;

  @ApiProperty({ example: 'updateDate', description: '更新时间' })
  @UpdateDateColumn({
    type: 'datetime',
    comment: '更新时间',
  })
  updateDate: string;

  @ManyToOne(() => GroupChat, (groupChat) => groupChat.group_id,{ eager: true })
  @JoinColumn({ name: 'group_id' })
  groupChat: GroupChat;

  @ManyToOne(() => ChatUser, (chatUser) => chatUser.id)
  @JoinColumn({ name: 'userId' })
  chatUser: ChatUser;
}
export class ChatUserGroupResult extends PaginatedResult {
  @ApiProperty({
    example: ChatUserGroup,
    type: [ChatUserGroup],
  })
  data: ChatUserGroup[];
  @ApiProperty({ example: 'pageSize', description: '数量' })
  pageSize: number;
  @ApiProperty({ example: 'pageNum', description: '页数' })
  pageNum: number;
  @ApiProperty({ example: 'total', description: '总数' })
  total: number;
}
